<?php

import('@.com.99ebc.lib.Logger');
import("@.com.99ebc.util.LittleTools");

import("ORG.Util.Page");

class MessageAction extends ParentAction {
    //当前操作的Model对像
    protected $_model = '';

    public function __construct() {
        parent::__construct();
        $this->_model       = D('Message');
        self::$templateDir    .= 'admin/';
        self::$publicDir      .= self::$skinName . '/' . 'admin/';
    }

    //添加记录
    public function add() {
        $data['message_id']    = '';
        $data['message_name']  = $_POST['message_name'];
        $data['message_phone'] = $_POST['message_phone'];
        $data['message_email'] = $_POST['message_email'];
        $data['message_desc']  = $_POST['message_desc'];
        $data['edit_time']     = mktime();
        $opResult       = $this->_model->addMessage($data);
        if(true === $opResult) {
            echo '0';
        } else {
            Logger::log('用户留言发送失败！' . var_export($_POST, true));
            echo '1|留言失败，服务器忙，请您稍后再试！';
        }
        exit;
    }
    
    //得到类对像
    protected function getClassObject() {
        return D(ucfirst($this->_curModel));
    }

    //设置当前模块的标题
    protected function assignPageTitle($actionPath) {
        $this->assign('modelTitle', $this->findModelTitle($actionPath));
    }

    //查找当前操作对应的名称
    protected function findModelTitle($modelName) {
        $models     = C('MODEL');
        if(array_key_exists($modelName, $models)) {
            return $models[$modelName];
        } 

        return '';
    }

}

?>
